{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Definition for a binary tree node.\n",
    "# class TreeNode(object):\n",
    "#     def __init__(self, x):\n",
    "#         self.val = x\n",
    "#         self.left = None\n",
    "#         self.right = None\n",
    "\n",
    "class Solution(object):\n",
    "    def binaryTreePaths(self, root):\n",
    "        \"\"\"\n",
    "        :type root: TreeNode\n",
    "        :rtype: List[str]\n",
    "        \"\"\"\n",
    "        btp = []\n",
    "        if root is None:\n",
    "            return btp\n",
    "        \n",
    "\n",
    "        def findTreePath(node, path):\n",
    "            if node.left is None and node.right is None:\n",
    "                btp.append(path+'->' + str(node.val))\n",
    "                return\n",
    "            if node.left:\n",
    "                findTreePath(node.left, path + '->' + str(node.val))\n",
    "            if node.right:\n",
    "                findTreePath(node.right, path + '->' + str(node.val))\n",
    "\n",
    "        if root.left:\n",
    "            findTreePath(root.left, str(root.val))\n",
    "        if root.right:\n",
    "            findTreePath(root.right, str(root.val))\n",
    "        \n",
    "        # Root itself is leaf\n",
    "        if len(btp) == 0:\n",
    "            btp.append(str(root.val))\n",
    "        \n",
    "        return btp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
